package com.bilibili.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bilibili.entity.Comment;
import com.bilibili.entity.CommonResult;
import com.bilibili.service.CommentService;
import com.bilibili.service.impl.CommentServiceImpl;

@SuppressWarnings("serial")
@WebServlet("/deleteCommentB")
public class DeleteCommentBServlet extends HttpServlet{
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("application/json; charset=utf-8");
		String commentId = request.getParameter("commentId");
		String state = request.getParameter("state");
		int comment_id = -1,status = -1;
		
		if(commentId != null && !"".equals(commentId)) {
			comment_id = Integer.parseInt(commentId);
		}
		if(state != null && !"".equals(state)) {
			if(state.equals("删除")) {
				status = 0;
			}else {
				status = 1;
			}
		}
		Comment c = new Comment();
		c.setCommentId(comment_id);
		c.setState(status);
		CommentService cs = new CommentServiceImpl();
		CommonResult cr = new CommonResult();
		if(cs.deleteCommentInfoByCId(c)) {
			cr.setCode(200);
		}else {
			cr.setCode(409);
		}
		response.getWriter().write(cr.toJSONString());
	}
}
